package scsys.webServlet.login;

import com.alibaba.fastjson.JSON;
import scsys.pojo.User;
import scsys.servlet.UserService;
import scsys.servlet.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;

@WebServlet("/login_check_Servlet")
public class login_check_Servlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1. 接收数据
        BufferedReader br = request.getReader();
        String params = br.readLine();//json字符串
        //转为user对象

        User user = JSON.parseObject(params, User.class);
        UserService userService = new UserServiceImpl();
        if (user == null){
            response.getWriter().write("no");
            return;
        }else {
            User selectUser = null;
            selectUser = userService.selectOne(user);
            System.out.println(selectUser.getUserName());;
            if(selectUser!=null){
                response.getWriter().write("yes");
            }else {
                response.getWriter().write("no");
            }
        }

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
